﻿/// displayStatusInfo
$.displayStatusInfo = function (statusInfo, autoHide) {

    var timerId = null;

    if (typeof statusInfo == 'string' && statusInfo == 'close') {
        if (timerId) {
            clearInterval(timerId);
        }
        $('.snap-status-info').remove();
    } else {

        if (autoHide == null) {
            autoHide = true;
        }

        var status = statusInfo.Status;
        var info = statusInfo.Info;

        var panelDom = $('<div class="snap-status-info">')
            .addClass(status)
            .hide()
            .append(info)
            .appendTo('body')
            .hide();

        var setPanelPositon = function () {
            var $pageHead = $('#page-head');
            if ($pageHead.length > 0) {
                var pos = $('#page-head').position();
                var width = $('#page-head').width();
                var panelWidth = panelDom.width();
                var scrollTop = $(document).scrollTop();
                panelDom.css({
                    left: pos.left + (width - panelWidth) / 2 + 'px',
                    top: pos.top - scrollTop < 0 ?  0 : pos.top - scrollTop
                });
            }
        };
        setPanelPositon();

        clearInterval(timerId);
        timerId = setInterval(setPanelPositon, 40);
        panelDom.show();

        if (autoHide) {
            setTimeout(function () {
                panelDom.fadeOut();
            }
                , 5000);
        }
    }
}


$.redirectAndDisplayInfo = function (targetUrl, statusInfo) {
    var formHtml = '<form id ="RedirectAndDisplayInfo" action="{targetUrl}" method=post>' +
                      '<input type="hidden" name="status" value="{statusValue}"/>' +
                      '<input type="hidden" name="info" value="{infoValue}"/>'
    '</form>';

    formHtml = formHtml.replace("{targetUrl}", targetUrl)
                       .replace("{statusValue}", statusInfo.Status)
                       .replace("{infoValue}", statusInfo.Info)

    $(formHtml)
      .appendTo('body')
      .submit();
}




